package config_center

import (
	"sync"
)

// AtomicString 字符串类型的配置值
type AtomicString struct {
	sync.RWMutex
	value string
}

func NewAtomicString(val string) *AtomicString {
	return &AtomicString{
		value: val,
	}
}

func (a *AtomicString) Store(newValue string) bool {
	a.Lock()
	defer a.Unlock()

	if a.value == newValue {
		return false
	}

	a.value = newValue

	return true
}

func (a *AtomicString) String() string {
	a.RLock()
	defer a.RUnlock()

	return a.value
}
